package com.ccb.sc.order.controller;

import com.ccb.sc.auth.TokenAuth;
import com.ccb.sc.auth.TokenModel;
import com.ccb.sc.order.service.AppOrderExchangeService;
import com.ccb.sc.order.vo.OrderExchangeCreateVo;
import com.ccb.sc.order.vo.OrderExchangeListVo;
import com.ccb.sc.common.bind.annotation.CurrentUser;
import com.ccb.sc.common.bind.page.PageParams;
import com.ccb.sc.common.bind.page.PageVo;
import com.ccb.sc.common.bind.response.ResBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author ken
 * @version 1.0
 * @date 2022/8/14 16:30
 */
@RestController
@TokenAuth
@RequestMapping("/app/order-exchange")
@Api(value = "订单转换管理", tags = "订单转换管理")
public class OrderExchangeController {

    @Autowired
    private AppOrderExchangeService appOrderExchangeService;

    @GetMapping("/list")
    @ApiOperation(value = "订单转换列表", response = OrderExchangeListVo.class, responseContainer = "list")
    public ResBody<?> list(@CurrentUser @ApiIgnore TokenModel token, PageParams queryParam) {
        PageVo<OrderExchangeListVo> result = this.appOrderExchangeService.selectOrderExchanges(token.getId(), queryParam);
        return ResBody.success(result);
    }

    @PostMapping("/create")
    @ApiOperation(value = "订单转换申请")
    public ResBody<?> create(@CurrentUser @ApiIgnore TokenModel token, @Validated @RequestBody OrderExchangeCreateVo createVo) {
        this.appOrderExchangeService.create(token.getId(), createVo);
        return ResBody.success();
    }

}
